package com.paw.ruoyi.admin.config;

import com.paw.ruoyi.admin.core.config.DefaultMybatisPlusConfig;
import com.paw.ruoyi.admin.core.config.WebInterceptorConfiguration;
import com.paw.ruoyi.admin.service.IFileUploadService;
import com.paw.ruoyi.admin.service.impl.AliyunOssService;
import com.paw.ruoyi.admin.service.impl.LocalFileUploadService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Rubble
 * @date 2022/1/12
 **/
@Configuration
@Import(value = { DefaultMybatisPlusConfig.class, WebInterceptorConfiguration.class})
public class WebConfiguration implements WebMvcConfigurer {


  @Bean
  public PasswordEncoder passwordEncoder(){
    return new BCryptPasswordEncoder();
  }


  @Bean
  @ConditionalOnProperty(prefix = "paw.storage",name = "type",havingValue = "oss")
  public IFileUploadService aliyunOssService(){
    return new AliyunOssService();
  }


  @Bean
  @ConditionalOnProperty(prefix = "paw.storage",name = "type",havingValue = "local",matchIfMissing = true)
  public IFileUploadService localFileUploadService(){
    return new LocalFileUploadService();
  }

}
